/**
 * @Title: SimpleThreadLocal.java
 * @Package com.yywz
 * @Description: TODO
 * @author Nick
 * @date Jul 13, 2012 10:07:11 PM
 * @version V1.0
 */
package com.yywz;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: TODO
 * @author guohao
 * @version Jul 13, 2012 10:07:11 PM
 */
public class SimpleThreadLocal {
	
	private Map map = Collections.synchronizedMap(new HashMap());
	
	public void set(Object value) {
		//键为线程对象 值为本地线程的变量副本
		map.put(Thread.currentThread(), value);
	}
	
	public Object get() {
		Thread currentThread = Thread.currentThread();
		Object object = map.get(currentThread);
		if (object == null && map.containsKey(currentThread)) {
			object = initalValue();
			map.put(currentThread, object);
		}
		return object;
	}
	
	public void remove() {
		map.remove(Thread.currentThread());
	}
	
	public Object initalValue() {
		return null;
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
